home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Cream of the Crop 22
/
Cream of the Crop 22.iso
/
program
/
pcl4c60.zip
/
XONOFF.C
< prev
next >
Wrap
Text File
|
1996-10-10
|
1KB
|
50 lines
/*
** XONOFF.C
**
** 1. XON/XOFF protocol can NOT be used with binary data.
** 2. Before using XioPutc() and XioGetc(), call XioSetup() with
** LoWater = 16, and HiWater = RX_QUEUE_SIZE - 16, where
** RX_QUEUE_SIZE is the queue size passed in SioRxBuf().
** 3. After calling XioSetup(), call XioPutc() and XioGetc()
** instead of SioPutc() and SioGetc().
*/
#include "pcl4c.h"
#include "xonoff.h"
#define XON 0x11
#define XOFF 0x13
static char LastXsent = XON;
static char LastXreceived = XON;
static int RxHiWater = 48;
static int RxLoWater = 16;
void XioSetup(int LoWater,int HiWater)
{RxLoWater = LoWater;
RxHiWater = HiWater;
LastXsent = XON;
LastXreceived = XON;
}
int XioPutc(int Port,char C)
{if(LastXreceived==XOFF) return -1;
return SioPutc(Port,C);
}
int XioGetc(int Port)
{int C;
C = SioGetc(Port,0);
if((C==XON)||(C==XOFF)) LastXreceived = C;
else switch(LastXsent)
{case XOFF:
if(SioRxQue(Port)<=RxLoWater) SioPutc(Port,LastXsent=XON);
break;
case XON:
if(SioRxQue(Port)>=RxHiWater) SioPutc(Port,LastXsent=XOFF);
break;
}
return C;
}